{% extends 'layout.html' %}

{% block title %}{% endblock %}

{% block css %}{% endblock %}

{% block content %}
<div id="wrap">
  <div class="wrap container">
    {% include "zujian/block.html" %}
    <main class="main">
      <article id="post-607"
        class="post-607 post type-post status-publish format-standard has-post-thumbnail hentry category-keji tag-19 tag-141">
        <div class="entry">
          <div class="entry-head">
            <h1 class="entry-title">{{data.title}}</h1>
            <div class="entry-info">
              <span class="vcard"> <a class="nickname url fn j-user-card"></a> </span>
              <span class="dot">•</span>
              <time class="entry-date published"> {{data.lastCommentTime}} </time>
              <span class="dot">•</span>
              <span>
                阅读
              </span>
            </div>
          </div>
          <style>
            .entry-content img {
              cursor: pointer;
            }
          </style>
          <div class="entry-content">
            <!-- txt -->
            {{data.content | safe }}

            {% for obj in data.attachments %}

            {% if obj.category == "video" %}

                <!-- 判断当前有没有视频链接 -->
                {% if obj.remoteUrl != "" %}
                <h4 style="color: red; font-size:20px;margin: 30px 0;text-align: center;">
                  yy提示下：很抱歉，由于技术方面的限制，我们目前仅能为您提供视频的预览版，尚无法提供完整的破解版视频。对于由此可能给您带来的不便，我们深感歉意，并希望得到您的谅解。我们将持续努力改进技术，争取在未来为您提供更好的服务。感谢您的理解与支持。</h4>
                <video id="video" controls style="width: 100%;height:300px;"></video>
                <script>
                  var video = document.getElementById('video');
                  if (Hls.isSupported()) {
                    var hls = new Hls({
                      debug: true,
                    });
                    hls.loadSource("{{Domain}}{{obj.remoteUrl}}");
                    hls.attachMedia(video);
                    hls.on(Hls.Events.MEDIA_ATTACHED, function () {
                      video.muted = true;
                      // video.play();
                    });
                  }
                </script>
              {% else %}
              <!-- <h4 style="color: red; font-size:20px;margin: 30px 0;text-align: center;">
                yy提示: 当前帖子无视频，点击 <a href="{{HDomain}}" style="color: orange;">此处</a> 可前往官网，如有不同之处可联系客服进行修复：</h4> -->
              <button type="button" style="margin: 30px 0;" class="layui-btn layui-btn-fluid" onclick="GETVIDEO('{{obj.id}}',this)">尝试获取视频</button>
            {% endif %}
            {% endif %}




            {% endfor %}
            <!-- txt -->
            <!-- content -->
            <div class="entry-copyright">
              <p>测试爬虫效果, 只做测试使用。发布者: yy<span></span></p>
            </div>
          </div>
          <div class="entry-footer">
            <div class="entry-tag">
              {% for i in data.tags %}
              <a href="#">{{i.tagName}}</a>
              {% endfor %}
            </div>
            <!-- {% include "zujian/上一篇-下一篇.html" %} -->


            <!-- {% include "zujian/相关推荐.html" %} -->

          </div>
        </div>
      </article>
    </main>

  </div>
</div>

{% endblock %}

{% block js %}

<script>

  window.onload = function () {
    let lis = document.querySelectorAll("img");
    for (let i = 0; i < lis.length; i++) {
      let ss = lis[i].src;
      // p(ss,lis[i].querySelector('div .item-img a img') )
      let hoz = ss.substr(-3);
      if (hoz == "txt") {
        p(ss, lis[i])
      }
    }

    let saas = document.querySelectorAll("img");
    for (let i = 0; i < saas.length; i++) {

      saas[i].addEventListener('click', (e) => {
        layer.photos({
          photos: {
            "title": "Photos Demo",
            "start": 0,
            "data": [
              {
                "alt": "layer",
                "pid": 1,
                "src": e.target.src,
              }
            ],

          },
          footer: false
        });
      })
    }


  }

</script>
<script>
function asdasda(aass) {
              var video = document.getElementById('video');
              console.log(video);
       setTimeout(() => {
               if (Hls.isSupported()) {
                var hls = new Hls({
                  debug: true,
                });
                hls.loadSource(aass);
                hls.attachMedia(video);
                hls.on(Hls.Events.MEDIA_ATTACHED, function () {
                  video.muted = true;
                  // video.play();
                });
              }
       }, 1500);
}
  function GETVIDEO(imgid,sssa) {
    var loadIndex = layer.msg('加载中', {
        icon: 16,
        shade: 0.9
      });
    axios({
      url: "/yyty/news/info/",
      method: "POST",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        "ImageID": imgid,
        "TzID": "{{pid}}"
      }
    }).then(res => {
      console.log(res);
      m3u8_url = res.data.remoteUrl;
      let entry_content = document.querySelector(".entry-content");
      console.log(entry_content);
      // 创建一个新的video元素  
      var video = document.createElement('video');
      var h4 = document.createElement('h4');
      h4.style=`color: red; font-size:20px;margin: 30px 0;text-align: center;`;
      // 设置video元素的源，这里假设你有一个名为'myVideo.mp4'的视频文件  
      // video.src = m3u8_url;

      // 添加controls属性，使得用户可以控制视频的播放  
      video.controls = true;
      video.id = "video";
      h4.innerHTML = "yy提示下：很抱歉，由于技术方面的限制，我们目前仅能为您提供视频的预览版，尚无法提供完整的破解版视频。对于由此可能给您带来的不便，我们深感歉意，并希望得到您的谅解。我们将持续努力改进技术，争取在未来为您提供更好的服务。感谢您的理解与支持。"
      // 获取body元素的最后一个子元素  
      var lastChild = document.body.lastChild;

      // 将video元素插入到body元素的最后  
      entry_content.insertBefore(video,sssa);
      entry_content.insertBefore(h4,sssa);
      asdasda(m3u8_url)
      layer.close(loadIndex)
    }).catch(roor => {
      console.log(roor);
    })
  }
</script>
{% endblock %}